package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划相关接口")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    // 分页查询护理计划
    @GetMapping("/plan/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse> selectByPage(
            Integer pageNum,
            Integer pageSize,
            String name,
            Integer status// 状态：0：禁用，1：启用
    ) {
        return ResponseResult.success(nursingPlanService.selectByPage(pageNum, pageSize, name, status));
    }

    // 新增护理计划
    @PostMapping("/plan")
    @ApiOperation("新增护理计划")
    public ResponseResult create(@ApiParam(value = "护理计划数据传输对象", required = true)
                                 @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.savePlan(nursingPlanDto);
        return ResponseResult.success();
    }

    // 根据id查询护理计划
    @ApiOperation("根据ID查询护理计划")
    @GetMapping("/plan/{id}")
    public ResponseResult<NursingPlanVo> getNursingPlanById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id) {
        return ResponseResult.success(nursingPlanService.getById(id));
    }

    // 根据id删除护理计划
    @DeleteMapping("/plan/{id}")
    @ApiOperation("根据id删除护理计划")
    public int removeById(@PathVariable Long id) {
        return nursingPlanService.removeById(id);
    }

    // 根据id修改护理计划
    @PutMapping("/plan/{id}")
    @ApiOperation(value = "根据id修改护理计划")
    public ResponseResult updateById(@RequestBody NursingPlanDto nursingPlanDto) {
        BeanUtil.copyProperties(nursingPlanDto, NursingPlan.class);
        nursingPlanService.updateById(nursingPlanDto);
        return ResponseResult.success(nursingPlanDto);
    }

    // 启动或禁用
    @PutMapping("/plan/{id}/status/{status}")
    @ApiOperation("启动计划/禁用计划")
    public ResponseResult isEnable(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id,
            @ApiParam(value = "状态，0：禁用，1：启用", required = true)
            @PathVariable Integer status) {
        nursingPlanService.isEnable(id, status);
        return ResponseResult.success();
    }

    // 查询所有计划
    @GetMapping("/plan")
    @ApiOperation("查询所有护理计划")
    public ResponseResult selectAll() {
        List<NursingPlanVo> list = nursingPlanService.selectAll();
        return ResponseResult.success(list);
    }

}
